package com.ruoyi.book.controller;

import java.util.List;

import com.ruoyi.book.service.ITbBookListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.TbBookBorrow;
import com.ruoyi.book.service.ITbBookBorrowService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-01-11
 */
@Controller
@RequestMapping("/book/borrow")
public class TbBookBorrowController extends BaseController
{
    private String prefix = "book/borrow";

    @Resource
    private ITbBookBorrowService tbBookBorrowService;
    @Resource
    private ITbBookListService tbBookListService;

    @RequiresPermissions("book:borrow:view")
    @GetMapping()
    public String borrow()
    {
        return prefix + "/borrow";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("book:borrow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbBookBorrow tbBookBorrow)
    {
        startPage();
        List<TbBookBorrow> list = tbBookBorrowService.selectTbBookBorrowList(tbBookBorrow);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("book:borrow:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbBookBorrow tbBookBorrow)
    {
        List<TbBookBorrow> list = tbBookBorrowService.selectTbBookBorrowList(tbBookBorrow);
        ExcelUtil<TbBookBorrow> util = new ExcelUtil<TbBookBorrow>(TbBookBorrow.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add(Long bookId, ModelMap map)
    {
        TbBookBorrow tbBookBorrow = tbBookBorrowService.selectTbBookListByBookId(bookId);
        map.put("tbBookBorrow", tbBookBorrow);
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("book:borrow:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbBookBorrow tbBookBorrow)
    {
        return toAjax(tbBookBorrowService.insertTbBookBorrow(tbBookBorrow));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbBookBorrow tbBookBorrow = tbBookBorrowService.selectTbBookBorrowById(id);
        mmap.put("tbBookBorrow", tbBookBorrow);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("book:borrow:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbBookBorrow tbBookBorrow)
    {
        return toAjax(tbBookBorrowService.updateTbBookBorrow(tbBookBorrow));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("book:borrow:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbBookBorrowService.deleteTbBookBorrowByIds(ids));
    }


    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("book:borrow:still")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @GetMapping( "/still")
    @ResponseBody
    public AjaxResult still(Long id)
    {
        return toAjax(tbBookBorrowService.still(id));
    }



}
